home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / bor_ti.exe / TI1159.ASC < prev    next >
Encoding:
Text File  |  1992-11-11  |  11.0 KB  |  463 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1159
  9.   VERSION  :  3.1
  10.        OS  :  DOS
  11.      DATE  :  November 11, 1992                        PAGE  :  1/7
  12.  
  13.     TITLE  :  Graying Buttons with Turbo Vision.
  14.  
  15.  
  16.  
  17.  
  18.  
  19.        The following source code provides an example of graying a
  20.   button when using Borland's C++ Turbo Vision Framework for DOS.
  21.   A MAKEFILE is also included.
  22.  
  23.  
  24.   /****************************************************************
  25.   *                                                               *
  26.    * BUTTON.CPP                                                   *
  27.    *   This module contains code to set up a dialog box with three*
  28.    *   buttons. The first button toggles the second button between*
  29.    *   an enabled and disabled state.  The third is just an OK    *
  30.    *   button to  close the box.                                  *
  31.    *                                                              *
  32.    * SUPPORT MODULE for grey button example.                      *
  33.    *                                                              *
  34.    ****************************************************************
  35.    *                                                              *
  36.    * This code was written by Borland Technical Support.          *
  37.    * It is provided as is with no warranties expressed or implied *
  38.    *                                                              *
  39.    ***************************************************************/
  40.  
  41.   #define Uses_TRect
  42.   #define Uses_TView
  43.   #define Uses_TEvent
  44.   #define Uses_TButton
  45.   #define Uses_TLabel
  46.   #define Uses_TDialog
  47.   #define Uses_MsgBox
  48.   #include <tv.h>
  49.  
  50.   #pragma hdrstop
  51.  
  52.   #include "button.h"
  53.   #include "cmds.h"
  54.  
  55.  
  56.   /****************************************************************
  57.    *                                                              *
  58.    * class TButtonDialog                                          *
  59.    *                                                              *
  60.    ****************************************************************
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1159
  75.   VERSION  :  3.1
  76.        OS  :  DOS
  77.      DATE  :  November 11, 1992                        PAGE  :  2/7
  78.  
  79.     TITLE  :  Graying Buttons with Turbo Vision.
  80.  
  81.  
  82.  
  83.  
  84.    * TButtonDialog::TButtonDialog                                 *
  85.    *   Initialize the dialog box - add the appropriate labels and *
  86.    *   buttons and set option to center it on the screen.         *
  87.    ****************************************************************/
  88.  
  89.   TButtonDialog::TButtonDialog(TRect& r, char *title) :
  90.       TDialog( r, title ),
  91.       TWindowInit( initFrame )
  92.   {
  93.       TButton *TB;
  94.  
  95.       TB = new TButton( TRect(2,2,12,4), "~T~oggle", cmToggle,
  96.                         bfNormal );
  97.       insert( TB );
  98.       insert( new TLabel( TRect(13,2,37,3), "Toggle
  99.                       enabled/disabled", TB ) );
  100.  
  101.       TB = new TButton( TRect(2,4,12,6), "T~e~ster", cmTester,
  102.                       bfNormal );
  103.       insert( TB );
  104.       insert( new TLabel( TRect(13,4,25,5), "Test Button", TB ) );
  105.  
  106.       insert( new TButton( TRect(14,7,24,9), "O~K~", cmOK,
  107.                       bfDefault ) );
  108.  
  109.       options |= ofCentered;
  110.       selectNext( False );
  111.   }
  112.  
  113.  
  114.   /****************************************************************
  115.    * TTestList::handleEvent
  116.    *   Handle the command events from the <Toggle> and <Tester>
  117.        buttons.
  118.    ****************************************************************/
  119.  
  120.   void TButtonDialog::handleEvent( TEvent& event )
  121.   {
  122.       TDialog::handleEvent( event );
  123.  
  124.       if( event.what == evCommand )
  125.       {
  126.           switch( event.message.command )
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1159
  141.   VERSION  :  3.1
  142.        OS  :  DOS
  143.      DATE  :  November 11, 1992                        PAGE  :  3/7
  144.  
  145.     TITLE  :  Graying Buttons with Turbo Vision.
  146.  
  147.  
  148.  
  149.  
  150.           {
  151.           case cmToggle:             // Toggle tester button on/off
  152.               if( commandEnabled( cmTester ) )
  153.                   disableCommand( cmTester );
  154.               else
  155.                   enableCommand( cmTester );
  156.               break;
  157.  
  158.           case cmTester:             // Put up a message box...
  159.               messageBox( "Tester button pressed...",
  160.                           mfOKButton | mfInformation
  161.                         );
  162.               break;
  163.  
  164.           default:
  165.               return;
  166.           }
  167.           clearEvent(event);
  168.       }
  169.   }
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.   /****************************************************************
  182.    * BUTTON.H                                                     *
  183.    *   Header file to support BUTTON.CPP.  Contains the dialog    *
  184.    *   class                                                      *
  185.    *   used for the buttons.                                      *
  186.    *                                                              *
  187.    * HEADER FILE for grey button example.                         *
  188.    *                                                              *
  189.    ****************************************************************
  190.    *                                                              *
  191.    * This code was written by Borland Technical Support.          *
  192.    * It is provided as is with no warranties expressed or implied.*
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1159
  207.   VERSION  :  3.1
  208.        OS  :  DOS
  209.      DATE  :  November 11, 1992                        PAGE  :  4/7
  210.  
  211.     TITLE  :  Graying Buttons with Turbo Vision.
  212.  
  213.  
  214.  
  215.  
  216.    *                                                              *
  217.    ****************************************************************/
  218.  
  219.   class TButtonDialog : public TDialog
  220.   {
  221.   public:
  222.       TButtonDialog( TRect& r, char *title );
  223.       virtual void handleEvent( TEvent& event );
  224.   };
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.   /****************************************************************
  236.    * CMDS.H                                                       *
  237.    *   This module contains various commands used in the main     *
  238.    *   message  system (including the menu bar, status line, and  *
  239.    *   miscellaneous dialog boxes.)                               *
  240.    *                                                              *
  241.    * HEADER FILE for grey button example.                         *
  242.    *                                                              *
  243.    ****************************************************************
  244.    *                                                              *
  245.    * This code was written by Borland Technical Support.          *
  246.    * It is provided as is with no warranties expressed or implied.*
  247.    *                                                              *
  248.    ****************************************************************/
  249.  
  250.   #ifndef _CMDS_H
  251.   #define _CMDS_H
  252.  
  253.   const unsigned short cmButtonDialog = 100;
  254.   const unsigned short cmToggle       = 101;
  255.   const unsigned short cmTester       = 102;
  256.  
  257.   #endif
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Borland C++                           NUMBER  :  1159
  273.   VERSION  :  3.1
  274.        OS  :  DOS
  275.      DATE  :  November 11, 1992                        PAGE  :  5/7
  276.  
  277.     TITLE  :  Graying Buttons with Turbo Vision.
  278.  
  279.  
  280.  
  281.  
  282.   /****************************************************************
  283.    * TEST.CPP                                                     *
  284.    *   This module contains the Turbo Vision application code to  *
  285.    *   run this example.  It sets up the necessary menus to bring *
  286.    *   up the test module represented by this demo.               *
  287.    * TEST MODULE for grey button example.                         *
  288.    *                                                              *
  289.    ****************************************************************
  290.    *                                                              *
  291.    * This code was written by Borland Technical Support.          *
  292.    * It is provided as is with no warranties expressed or implied.*
  293.    *                                                              *
  294.    ****************************************************************/
  295.  
  296.   #define Uses_TRect
  297.   #define Uses_TKeys
  298.   #define Uses_TEvent
  299.   #define Uses_TDialog
  300.   #define Uses_TListViewer
  301.   #define Uses_TMenu
  302.   #define Uses_TMenuItem
  303.   #define Uses_TMenuBar
  304.   #define Uses_TDeskTop
  305.   #define Uses_TApplication
  306.   #include <tv.h>
  307.  
  308.   #pragma hdrstop
  309.  
  310.   #include "cmds.h"
  311.   #include "button.h"
  312.  
  313.  
  314.   class TTestApp : public TApplication
  315.   {
  316.  
  317.   public:
  318.  
  319.       TTestApp() : TApplication(),
  320.                    TProgInit( initStatusLine, initMenuBar,
  321.                               initDeskTop ) {}
  322.       static TMenuBar *initMenuBar( TRect r );
  323.       virtual void handleEvent( TEvent& event );
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.   PRODUCT  :  Borland C++                           NUMBER  :  1159
  339.   VERSION  :  3.1
  340.        OS  :  DOS
  341.      DATE  :  November 11, 1992                        PAGE  :  6/7
  342.  
  343.     TITLE  :  Graying Buttons with Turbo Vision.
  344.  
  345.  
  346.  
  347.  
  348.   };
  349.  
  350.  
  351.   TMenuBar *TTestApp::initMenuBar( TRect r )
  352.   {
  353.       r.b.y = r.a.y + 1;
  354.       return new TMenuBar( r, new TMenu(
  355.           *new TMenuItem( "~B~utton Dialog", cmButtonDialog, kbAltL
  356.                            )
  357.           ));
  358.   }
  359.  
  360.  
  361.   void TTestApp::handleEvent( TEvent& event )
  362.   {
  363.       TApplication::handleEvent( event );
  364.  
  365.       if( event.what == evCommand &&
  366.           event.message.command == cmButtonDialog
  367.         )
  368.       {
  369.           TView *TBD = (TView *) validView(
  370.             new TButtonDialog( TRect(0,0,39,10), "Buttons")
  371.             );
  372.           if( TBD != 0 )
  373.               deskTop->execView( TBD );
  374.           clearEvent( event );
  375.       }
  376.   }
  377.  
  378.  
  379.   int main()
  380.   {
  381.       TTestApp TB;
  382.       TB.run();
  383.       return 0;
  384.   }
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.   PRODUCT  :  Borland C++                           NUMBER  :  1159
  405.   VERSION  :  3.1
  406.        OS  :  DOS
  407.      DATE  :  November 11, 1992                        PAGE  :  7/7
  408.  
  409.     TITLE  :  Graying Buttons with Turbo Vision.
  410.  
  411.  
  412.  
  413.  
  414.   #
  415.   # Makefile for Turbo Vision demo applications
  416.   #
  417.   # Written by Borland Tech Support, 1992.
  418.   #
  419.   .AUTODEPEND
  420.  
  421.   NAME    = testapp
  422.   OBJS    = $(NAME).obj button.obj
  423.  
  424.   BCROOT  = C:\BORLANDC
  425.   INCPATH = $(BCROOT)\include;$(BCROOT)\TVISION\include
  426.   LIBPATH = $(BCROOT)\lib;$(BCROOT)\TVISION\lib
  427.  
  428.   CFLAGS  = -c -I$(INCPATH) -H=$(NAME).sym -v -ml
  429.   LFLAGS  =  /v -Vt -L$(LIBPATH)
  430.   CC      = bcc
  431.   LINK    = tlink
  432.  
  433.   .cpp.obj:
  434.       $(CC) $(CFLAGS) {$< }
  435.  
  436.  
  437.   $(NAME).exe: $(OBJS)
  438.       $(LINK) @&&~
  439.   $(LFLAGS) c0l $(OBJS)
  440.   $(NAME).exe
  441.   $(NAME).map
  442.   tv emu mathl cl
  443.   ~
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.   DISCLAIMER: You have the right to use this technical information
  451.   subject to the terms of the No-Nonsense License Statement that
  452.   you received with the Borland product to which this information
  453.   pertains.
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.